<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
	.field a { color:#013d79 ;text-decoration:none;}
	.field a:hover { color:#013d79 ;text-decoration:underline;}
	.ellipsis{
	    overflow: hidden;
	    text-overflow: ellipsis;
	    white-space: nowrap;
	 }
</style>
</head>
<body class="iframeBody">
 <div class="Wrapper">
        <div>
           <div id="pageInTab" class="pageInTab">
		   <div tabid="tabA" title="基本信息" >
					<iframe frameborder="0" name="tabA" id="tabA" src=""></iframe>
				</div>
              <div tabid="tabB" title="资产包信息" id="tabBId" style="display: none;">
                    <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
             </div>
              <div tabid="tabC" title="首付款信息" id="tabCId" style="display: none;">
                    <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
             </div>
             <div tabid="tabD" title="还款信息" id="tabDId" style="display: none;">
                    <iframe frameborder="0" name="tabD" id="tabD" src=""></iframe>
             </div>
             <div tabid="tabE" title="合同管理" id="tabEId"  lselected="true">
                    
           <form id="fnc_prj_cont_form" >
             <div class="fieldset1 tabel_col clearFix">
             <div class="caption">
						<span class="title">项目基础信息</span>
					</div>
              <div class="fieldBox col_50">
                 <div class="label">项目名称</div>
                <div class="field">
                    <span id="fncprjnm" name="fncprjnm">&nbsp;${prjScmCr.FNC_PRJ_NM}</span>
                </div>
             </div>
                <div class="fieldBox col_50">
                 <div class="label">金融机构</div>
                <div class="field">
                     <span id="fncinsNM" name="fncinsNM">&nbsp;${prjScmCr.FUND_RAS_INS_NM}</span>
                </div> 
             </div>
                <div class="fieldBox col_50">
                    <div class="label">授信名称</div>
                    <div class="field">
                  <span id="instypeNM" name="instypeNM">&nbsp; <a href="javascript:showDetailCr(${prjScmCr.CR_ID_KEY});" >${prjScmCr.CR_NM}</a></span>
                </div>
             </div>
             <div class="fieldBox col_50">
              <div class="label">融资报价</div>
                <div class="field">
                 <span id="fncscmNM" name="fncscmNM">&nbsp;<a href="javascript:showDetailPrice(${prjScmCr.FNC_SCM_ID});" >${prjScmCr.FNC_SCM_NM}</a></span>
               </div>
             </div>
           
		 <div class="fieldBox col_50">
                <div class="label">业务类型</div>
                <div class="field">
                <span id="bustypeNM" name="bustypeNM">&nbsp;${prjScmCr.BUS_TYPE_}</span>
                </div>
                <div style="display: none">
                </div>
              </div>
          <div class="fieldBox col_50">
           <div class="label">实际融资金额</div>
            <div class="field">
                <span id="acFiAmt" name="acFiAmt"></span>
            </div>
          </div> 
          <div class="fieldBox col_50">
           <div class="label">首付款金额</div>
            <div class="field">
                <span id="firstPayment" name="firstPayment"></span>
            </div>
          </div> 
          
          <div class="fieldBox col_50">
             <div class="label">实际到账金额</div>
             <div class="field">
                   <span id="transAm" name="transAm"></span>
             </div>
          </div> 
         <div class="fieldBox col_50">
           <div class="label">到账日期</div>
            <div class="field">
                <span >&nbsp;${prjScmCr.TRANS_TM_}</span>
            </div>
          </div>
          
            <div class="caption">
				<span class="title">到账明细</span>
			</div>
        	<div class="fieldBox col_100">
					<div id="cost1" class="sq-grid" />
			</div>
			
          <div class="caption">
				<span class="title">合同明细</span>
		  </div>
		  <div class="fieldBox col_100">
					<div id="contDetail" class="sq-grid" />
			</div>
			
           </div>
         </form>
             </div>
        </div>
        </div>
    </div>
    
	<script type="text/javascript">
	var contDetailGrid;
	var pageInTab = null;
	var loadedTabs=[];
	var pageInApp={
	    		flag:true
	};
	$(function () {
		initTab();
	    $("#acFiAmt").html(fmoney(new  Number("${prjScmCr.AC_FI_AMT}")/100, 2));
	    $("#firstPayment").html(fmoney(new  Number("${prjScmCr.firstPayment}")/100, 2));
	    $("#transAm").html(fmoney(new  Number("${prjScmCr.TRANS_AM}")/100, 2));
	    
	    var expwddate ="${fncPrjBscInfo.expwddate}";
		if(null != expwddate&&expwddate!=''){
			var date = new Date(expwddate);
			$("#expwddate").text(DateUtils.formatDate(date, DateUtils.YYYY_MM_DD));
		}
	
		//初始化到账明细
		var id="${prjScmCr.ID}";
		if(id != "") {
			$("#cost1").ligerGrid({
	    		url:"<%=path%>/rfbuss/fncprjdrawmon/initList.do?id="+id,
	            method: 'get',
	                columns: [
		                { display: '到账日期', name: 'dmTm', width: 250,format: 'yyyy-MM-dd', editor: { type: 'date'},render:renderDate }, 
		                { display: '到账金额', name: 'dmAm',
		                    editor: { type: 'text' }, align: 'left', width: 280,totalSummary:{
		                        render: function (suminf, column, cell){
		                        	$("#transanttem").val(suminf.sum); 
		                            return '<div>总计:' + suminf.sum.toFixed(2) + '</div>';
		                        },
		                        align: 'right'
		                    }
		                },
		                { display: '收款银行', name: 'dueBank',
		                    editor: { type: 'text',readonly:true  }, align: 'left', width: 580
		                },
		                { display: '收款账号', name: 'dmAcc', 
		                    editor: { type: 'text',readonly:true }, align: 'left', width: 200
		                },
		                { display: '账号编号', name: 'accId',hide: true, 
		                    editor: { type: 'text' }, align: 'left', width: 180
		                }			               
	                ],
	                onSelectRow: function (rowdata, rowindex)
	                {
	                },
	                usePager: false,
	                root: 'rows',
	                record: 'total',
	                hideLoadButton: true,
	                width: '100%',
	                height: 300,
	                heightDiff: -2,
	                enabledEdit: false,
	                isScroll: false,
	                checkbox: true,
	                rownumbers: true,
	                allowUnSelectRow: true,
	                alternatingRow: false,
	                enabledSort: false
	            }); 
		}
		
		
		
		//初始化合同明细
		contDetailGrid = $("#contDetail").ligerGrid({
    		url:"<%=path%>/rfcont/fncPrjContAudit/contDetailList.do?contId=${prjScmCr.PCM_ID}",
            method: 'get',
                columns: [
                    { display: '合同名称', name: 'CONT_DETAIL_NM'},
                    { display: '合同附件', name: 'contDetailAttachList', isEllipsis: false,
                        render: function (rowdata, rowindex, value) {
                            var h = '<ul class="gridNanoItems">';
                            $(value).each(function(index, el) {
                                h = h + '<li class="ellipsis"><a class="curPointer" href="javascript:downFile(';
                                h+="'"+el.filePath+"'";
                                h+=",'"+el.fileNm+"'";
                                h+=')">'+el.fileNm+'</a></li>';
                            });
                            return h + '</ul>';
                        }
                    },
                    { display: '审核状态', name: 'CONT_DETAIL_STATUS_DES' },
                    { display: '风控审核附件', name: 'contDetailRiskAttachList', isEllipsis: false,
                        render: function (rowdata, rowindex, value) {
                            var h = '<ul class="gridNanoItems">';
                            $(value).each(function(index, el) {
                            	 h = h + '<li class="ellipsis"><a class="curPointer" href="javascript:downFile(';
                                 h+="'"+el.filePath+"'";
                                 h+=",'"+el.fileNm+"'";
                                 h+=')">'+el.fileNm+'</a></li>';
                            });
                            return h + '</ul>';
                        }
                    },
                    { display: '最终版', name: 'prjContDetailFinal' ,
                    	render: function (rowdata, rowindex, value){
                    		var h = "";
                    		if(value) {
                    			h+= '<a class="sq-button-hasicon" href="javascript:downFile(';
                                h+="'"+value.filePath+"'";
                                h+=",'"+value.fileNm+"'";
                                h+=')">'+value.fileNm+'</a>';
                    		}
            				return h;
            			}},
                    { display: '风控意见', name: 'prjContOptionList' ,width:180,
                        	render: function (rowdata, rowindex, value){
                        		var h = '<ul class="gridNanoItems">';
                                $(value).each(function(index, el) {
                                    h = h + '<li class="gridNanoItem2"><div class="ellipsis TL">' + el.CONT_DETAIL_OPINION + '</div>' +
                                        '<div class="TL info">' + el.CRT_TM_ +' '+el.USR_NM +' '+el.RL_NM + '</div></li>'
                                });
                                return h + '</ul>';
                		}},
                    { display: '操作', render:function (rowdata, rowindex, value){
                    		var h="";
	                    		<c:if test="${from=='riskControl' || from=='riskControlManager'}">
		                    		h+='<a class="sq-button-hasicon" href="javascript:contDetailView(';
					                h+="'"+rowdata.ID+"','audit'";
					                h+=")\"><i class='sqBtnIco_4'></i>审核</a>";
	                	    	</c:if>
				                h+='<a class="sq-button-hasicon" href="javascript:contDetailView(';
				                h+="'"+rowdata.ID+"','view'";
				                h+=")\"><i class='sqBtnIco_4'></i>查看</a>";
							return h;
						}
                    }               
                ],
                root: 'rows',
                record: 'total',
                pageSize:10,
                width: '100%',
                fixedCellHeight: false,
                frozen: false,
                checkbox:false,
                rownumbers:true,
                onAfterShowData: function () {
                    $(".gridTip").grid_ligerTip();
                    setNanoScroller();
                    SetIframe_height ();
                }
            }); 
		
		
	});
	
	 function setNanoScroller () {
         $('.gridNanoItems').each(function(index, el) {
             if ($(el).height() > 100 ) {
            	 $(el).wrap('<div class="gridNanoContainer"><div class="nano"><div class="nano-content">');
                 $(el).parents('.gridNanoContainer').height(100);
                 $(".nano").nanoScroller({
                     preventPageScrolling: true
                 });
             };
         });
     }
	 
	//合同明细详情
	function contDetailView(contDetailId,operate) {
		var url = '<%=path%>/rfcont/fncPrjContAudit/contDetailView.do?from=${from}&contDetailId='+contDetailId+'&operate='+operate ;
		Add_navTab("contDetailView"+contDetailId+operate, "合同明细详情", url, function () {
			contDetailGrid.reload();
		});
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//初始化Tab
    function initTab(){
    	 pageInTab = $("#pageInTab").ligerTab({
             height: 'auto',
             contextmenu: false,
             minIframeHeight: GET_minIframeHeight(),
             onBeforeSelectTabItem: function (tabid) {
             
             },
             onAfterSelectTabItem: function(tabid) {
                     loadedTabs.push(tabid);
                     switch (tabid){
	                     case "tabA":
	                    	 pageInTab.setTabItemSrc(tabid, "<%=path%>/rfbuss/fncprjbscinfo/toDetailPage2.do?id=${prjScmCr.ID}");
                         break;
                         case "tabB":
                        	 pageInTab.setTabItemSrc(tabid, "<%=path%>/rfbuss/fncprjbscinfo/viewAssPackInfoDetail.do?prjid=${prjScmCr.ID}&flag=2");
                             break;
                         case "tabC":
                        	 pageInTab.setTabItemSrc(tabid, "<%=path%>/rfbuss/fncprjbscinfo/tofstpyDetailPage.do?fncPrjId=${prjScmCr.ID}");
                             break;  
                         case "tabD":
                        	 pageInTab.setTabItemSrc(tabid, "<%=path%>/rfbase/fncprjpaysch/toRepayModifyPage.do?projid=${prjScmCr.ID}");
                             break;
                     }
                 SetIframe_height();
             }
         });

         $.extend(true, pageInApp, {
             pageInTab: pageInTab
         });
    };
    function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
    
  	//授信详情
	function showDetailCr(id){
		Add_navTab('PrdSpl_3'+id,'授信详情','<%=path%>/rfbase/crbaseinfo/toDetailPage.do?lgcId='+id);
	}
	//报价详情
	function showDetailPrice(id){
		Add_navTab('PrdPrice'+id,'报价详情','<%=path%>/rfbase/scmbaseinfo/toDetail.do?id='+id);
	}
	
	 //下载文件方法
	function downFile(_url,_name){
		if(SQ.regs.img.test(_name)){
			SQ.imgPreview(_url, true);
		}else{
			window.open(_url);
		}
	}
	</script>
</body>
</html>